package
{
	import flash.display.Sprite;
	import com.jidolstar.astro.*;	

	/**
	 * Nutation(장동운동) 테스트
	 * @author Yongho, Ji
	 * @since 2009.05.12
	 */ 
	public class testNutation extends Sprite
	{
		public function testNutation()
		{
			super();
			
			trace( "================================ test Nutation ====================================");
			var JDE:Number = 2446895.5;
			var nutation:ALNutation = new ALNutation( JDE, ALNutation.HIGH_ACCURACY, ALNutation.LONG_PERIOD );
			trace( "JDE: " + nutation.JDE ); //JDE: 2446895.5
			trace( "accurcy: " + nutation.accuracy ); //accurcy: highAccuracy
			trace( "period: " + nutation.period ); //period: longPeriod
			trace( "Δψ : " + nutation.longitude * ALConst.R2S); //Δψ : -3.787917163078442
			trace( "Δε : " + nutation.obliquity * ALConst.R2S); //Δε : 9.442520698757397
			trace( "ε0 : " + ALDMS.fractionalDegree2DMS( nutation.meanObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε0 : 23° 26’ 27”.37
			trace( "ε  : " + ALDMS.fractionalDegree2DMS( nutation.trueObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε  : 23° 26’ 36”.81
			
			//JDE는 같지만 적용기간을 길게 잡는다. 이는 오랜 시간이 지나도 오차를 적게내도록 한다.
			nutation.accuracy = ALNutation.HIGH_ACCURACY;
			nutation.period = ALNutation.SHORT_PERIOD;
			trace( "JDE: " + nutation.JDE ); //JDE: 2446895.5
			trace( "accurcy: " + nutation.accuracy ); //accurcy: highAccuracy
			trace( "peroid: " + nutation.period ); //peroid: shortPeriod
			trace( "Δψ : " + nutation.longitude * ALConst.R2S); //Δψ : -3.787917163078442
			trace( "Δε : " + nutation.obliquity * ALConst.R2S); //Δε : 9.442520698757397
			trace( "ε0 : " + ALDMS.fractionalDegree2DMS( nutation.meanObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε0 : 23° 26’ 27”.41
			trace( "ε  : " + ALDMS.fractionalDegree2DMS( nutation.trueObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε  : 23° 26’ 36”.85
			
			//2028년 11월 13.19일 UT1
			var date:ALDate = new ALDate( 2028, 11, 13.19 );
			var deltaT:Number = ALDynamicalTime.deltaT( date.fractionalYear );
			JDE = date.JD + deltaT / 3600;
			nutation.JDE = date.JD;
			trace( "JDE: " + nutation.JDE ); //JDE: 2462088.689583333
			trace( "accurcy: " + nutation.accuracy ); //accurcy: highAccuracy
			trace( "peroid: " + nutation.period ); //peroid: shortPeriod
			trace( "Δψ : " + nutation.longitude * ALConst.R2S); //Δψ : 14.860843903561848
			trace( "Δε : " + nutation.obliquity * ALConst.R2S); //Δε : 2.7046046954480025
			trace( "ε0 : " + ALDMS.fractionalDegree2DMS( nutation.meanObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε0 : 23° 26’ 07”.93
			trace( "ε  : " + ALDMS.fractionalDegree2DMS( nutation.trueObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε  : 23° 26’ 10”.64 
			
			//Nutation이 적용된 Matrix를 받아와 별의 적경(2h24m11.331s=41°.5472),적위(+49°20'54".54=+49°.3485)에 적용
			//Astronomical Algorithms 2nd p.153 
			var equNutationMatrix:ALMatrix3D = nutation.getNutationOfEquMatrix();
			var RA:Number = 41.5472 * ALConst.D2R;
			var DE:Number = 49.3485 * ALConst.D2R;
			var equVector:ALVector3D = new ALVector3D( RA, DE, 1, ALVector3D.COORDINATE_TYPE_SPHERICAL );
			var equNutationVectorArray:Array = equNutationMatrix.multiply3x3ByVector3D( [equVector] );
			var equNutationVector:ALVector3D = equNutationVectorArray[0];
			trace( "RA : " + ALHMS.fractionalHour2HMS( equNutationVector.longitudeHour ).toString("h","m","s") ); //RA : 02h46m12.38s
			trace( "DE : " + ALDMS.fractionalDegree2DMS( equNutationVector.latitudeDegree ).toString() ); //DE : 49° 21’ 00”.82
			trace( "dRA : " + (equNutationVector.longitude - RA) * ALConst.R2S ); //dRA : 15.843198038325333
			trace( "dDE : " + (equNutationVector.latitude - DE) * ALConst.R2S ); //dDE : 6.217170560031128			
		}
		
	}
}